<?php

class FuncaoDao extends Dao {

    public function injectDependencies() {

    }

    //##24-01
    public function findById($IDPosition) {
        $this->initConnection();
        $this->tMysqli->escape($IDPosition);
        $StSql = TQuery::getSqlPositionLoad($IDPosition);
        $tQuery = $this->tMysqli->exec($StSql);
        while( $ArPositionData = mysqli_fetch_assoc($tQuery) ) {
            $Funcao = new Funcao($ArPositionData['IDFuncao'], $ArPositionData['StFuncao'], $this->tMysqli);
            $Funcao->loadAllProfiles();
        }
        $this->closeConnection();
        return !empty($Funcao) ? $Funcao : false;
    }

    public function findSimpleById($IDPosition) {
        $this->initConnection();
        $this->tMysqli->escape($IDPosition);
        $StSql = TQuery::getSqlPositionLoad($IDPosition);
        $tQuery = $this->tMysqli->exec($StSql);
        while( $ArPositionData = mysqli_fetch_assoc($tQuery) ) {
            $Funcao = new Funcao($ArPositionData['IDFuncao'], $ArPositionData['StFuncao'], $this->tMysqli);
        }
        $this->closeConnection();
        return !empty($Funcao) ? $Funcao : false;
    }

     /**
     * @method  findAll
     *
     * Seleciona todas as funcoes cadastradas no sistema
     *
     * @since   2011-12-16
     * @return  array
     * @author  Richard Brandao <richardsbrandao@gmail.com>
     */
    public function findAll() {
        $ArPositions = array();
        $StSql = TQuery::getSqlFindAllPositions();
        $this->initConnection();
        $tQuery = $this->tMysqli->exec($StSql);
        while($ArPosition = mysqli_fetch_assoc($tQuery)) {
            $Funcao = new Funcao($ArPosition['IDFuncao'], $ArPosition['StFuncao'], $this->tMysqli);
            $Funcao->loadAllProfiles();
            $ArPositions[] = $Funcao;
        }
        $this->closeConnection();
        return $ArPositions;
    }

    public function save($StFuncao) {
        $StSql = TQuery::getSqlInsertPosition($StFuncao);
        $this->initConnection();
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function update($ArDados) {
        $StSql = TQuery::getSqlUpdatePosition($ArDados['IDFuncao'], $ArDados['StFuncao']);
        $this->initConnection();
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeTransaction();
        return $BoReturn;
    }

    public function delete($IDFuncao) {
        $this->initConnection();
        $StSql = TQuery::getSqlDeletePosition($IDFuncao);
        $this->tMysqli->exec($StSql);
        $BoRetorno = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoRetorno;
    }

}

?>
